package cn.stylefeng.guns.modular.time.controller;

import cn.stylefeng.guns.modular.time.entity.Budget;
import cn.stylefeng.guns.modular.time.model.request.BudgetRequest;
import cn.stylefeng.guns.modular.time.service.BudgetService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "预算管理")
public class BudgetController {

    @Resource
    private BudgetService budgetService;

    @GetResource(name = "分页查询预算", path = "/budget/page")
    public ResponseData<PageResult<Budget>> page(BudgetRequest request) {
        return new SuccessResponseData<>(budgetService.findPage(request));
    }

    @PostResource(name = "新增预算", path = "/budget/add")
    public ResponseData<Void> add(@RequestBody @Validated(BudgetRequest.add.class) BudgetRequest request) {
        budgetService.add(request);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑预算", path = "/budget/edit")
    public ResponseData<Void> edit(@RequestBody @Validated(BudgetRequest.edit.class) BudgetRequest request) {
        budgetService.edit(request);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除预算", path = "/budget/delete")
    public ResponseData<Void> delete(@RequestBody @Validated(BudgetRequest.delete.class) BudgetRequest request) {
        budgetService.delete(request);
        return new SuccessResponseData<>();
    }
}

